<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateVulsTable extends Migration
{
    /**
     * Run the migrations.
     * 漏洞内容
     * @return void
     */
    public function up()
    {
        Schema::create('vuls', function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_general_ci';

            $table->increments('id');
            $table->string('title',255)->comment('标题');
            $table->string('description',255)->comment('简述');

            $table->integer('user_id')->comment('提交人ID');
            $table->integer('app_id')->comment('应用ID');
            $table->integer('category_id')->comment('分类ID');
            $table->integer('level_id')->comment('级别ID');

            $table->text('content')->comment('漏洞内容');

            $table->integer('reward')->default(0)->comment('奖励: 安全币');
            $table->integer('credit')->default(0)->comment('奖励: 贡献度');
            $table->integer('status')->comment('状态: -1 declined 0 pending 1 confirmed 2 fixing 3 rechecking 4 done');

            $table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
            $table->timestamp('updated_at')->nullable();
            $table->integer('is_delete')->default(0)->comment('是否删除');
            $table->timestamp('delete_at')->nullable();

            $table->index('user_id','vuls_user_id_index');
            $table->index('category_id','vuls_category_index');
            $table->index('status','vuls_status_index');
            $table->index('reward','vuls_reward_index');
            $table->index('credit','vuls_credit_index');
            $table->index('created_at','vuls_created_at_index');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('vuls');
    }
}
